<?php 
require_once 'config/dbconfig.php';

if(isset($_GET['type']) && $_GET['type']=='delete'){
    $id = $_GET['id'];
    $query = "delete from auto_addrow where id= '$id'";
    $result = mysql_query($query);
    if($result == true){
        echo 'delete success full';
    }else{
        echo 'delete fail';
    }
}

$result = mysql_query("select * from auto_addrow");

if($result){
    $arrData = array();
    while($data = mysql_fetch_object($result)){
    
    
        $arrData['label'][] =$data->label;
        $arrData['number'][]=$data->number;
        $arrData['id'][]    =$data->id;
    }   
}

?>
<!DOCTYPE html>
<html>
<head>

<script type="text/javascript"
	src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
    	$('#add').click(function(){
    		$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
    	    $('#mytable tbody>tr:last #name').val('');
    	    return false;
        });

//        $('#delete').click(function(){
//            if($('#mytable tbody>tr').length >2){
//            	$('#mytable tbody>tr:last').remove();
//                
//                }   
//        });
    });
    
</script>
</head>
<body>

<form id="personas" name="personas" method="post" action="index.php">
<table width="300" border="1" cellspacing="0" cellpadding="2"
	id="mytable">
	<tbody>
		<tr>
			<td>Name</td>
			<td>Number</td>
			<td>Action</td>
		</tr>
		<?php foreach ($arrData['label'] as $index => $label): ?>
		<tr>
			<td><input type="text" name="name[]" value="<?php echo $label; ?>" /></td>
			<td><input type="text" name="number[]" value="<?php echo $arrData['number'][$index]; ?>" /></td>
			<td><a href="index.php?id=<?php echo $arrData['id'][$index]; ?>&type=delete" id="delete">Delete</a></td>
		</tr>
		<?php endforeach;?>
		<tr>
		    <td rowspan="4">
		      <input type="submit" value="Save" />
		    </td>
		</tr>
	</tbody>
</table>
</form>

<div id="chart"></div>
</body>
</html>
